﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EmailingList.Models;

namespace EmailingList.Controllers
{
    public class EmailsController : Controller
    {
        // GET: Emails
        public ActionResult Index()
        {
            var model = Enumerable.Range(1, 10)
                .Select(i => new EmailItem() 
                { 
                    Id = i,
                    Email = string.Format("john.smith{0}@microsoft.com", i),
                    FullName = string.Format("John Smith {0}", i)
                });

            return View(model);
        }

        // GET: Emails/Details/5
        public ActionResult Details(int id)
        {
            var model = new EmailItem()
            {
                Id = id,
                Email = string.Format("john.smith{0}@microsoft.com", id),
                FullName = string.Format("John Smith {0}", id)
            };
            return View(model);
        }

        // GET: Emails/Create
        public ActionResult Create()
        {
            return View();
        }

        // POST: Emails/Create
        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        // GET: Emails/Edit/5
        public ActionResult Edit(int id)
        {
            var model = new EmailItem()
            {
                Id = id,
                Email = string.Format("john.smith{0}@microsoft.com", id),
                FullName = string.Format("John Smith {0}", id)
            };
            return View(model);
        }

        // POST: Emails/Edit/5
        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        // GET: Emails/Delete/5
        public ActionResult Delete(int id)
        {
            return View();
        }

        // POST: Emails/Delete/5
        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
